#include <iostream>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;

void *ThreadRoutine(void *arg)
{
    const char *threadName = (const char *)arg;
    while (true)
    {
        cout << "I am a new thread" << ", pid: " << getpid() << ", " << threadName << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid1;
    pthread_create(&tid1, nullptr, ThreadRoutine, (void *)"thread 1");

    sleep(2);

    pthread_t tid2;
    pthread_create(&tid2, nullptr, ThreadRoutine, (void *)"thread 2");

    sleep(2);

    pthread_t tid3;
    pthread_create(&tid3, nullptr, ThreadRoutine, (void *)"thread 3");

    sleep(2);

    pthread_t tid4;
    pthread_create(&tid4, nullptr, ThreadRoutine, (void *)"thread 4");

    sleep(2);

    pthread_t tid5;
    pthread_create(&tid5, nullptr, ThreadRoutine, (void *)"thread 5");

    sleep(2);

    while (true)
    {
        cout << "I am main thread" << ", pid: " << getpid() << endl;
        sleep(1);
    }
    return 0;
}
